<style type="text/css">
    .table-bordered{
        margin-top: 20px;
    }
    a{cursor: pointer}
</style>

<div class="breadcrumbwidget">
	<ul class="skins">
        <li><a href="default" class="skin-color default"></a></li>
        <li><a href="orange" class="skin-color orange"></a></li>
        <li>&nbsp;</li>
        <li class="fixed"><a href="" class="skin-layout fixed"></a></li>
        <li class="wide"><a href="" class="skin-layout wide"></a></li>
    </ul><!--skins-->
	<ul class="breadcrumb">
        <li><a href="">Home</a> <span class="divider">/</span></li>
        <li class="active">Ưu đãi mới nhất</li>
    </ul>
</div><!--breadcrumbwidget-->
<div class="pagetitle">
	<h1>Ưu đãi mới nhất</h1> <span></span>
</div><!--pagetitle-->

<div class="maincontent">
	<div class="contentinner content-dashboard">
    
    <a class="btn btn-default" href="<?php echo $baseurl.'manage/incentive/add-incentives'?>">Thêm mới</a>
    


    <table class="table table-bordered">
        <colgroup>
            <col class="con0" />
            <col class="con1" />
            <col class="con0" />
            <col class="con1" />
            <col class="con0" />
            <col class="con1" />
            <col class="con0" />
            <col class="con1" />
            <col class="con0" />
        </colgroup>
        <thead>
            <tr>
            	<th class="centeralign"><input type="checkbox" class="checkall" /></th>
                <th style="width: 200px;">Tên ưu đãi</th>
                <th class="imet">Ảnh ưu đãi</th>
                <th style="width: 200px;">Tóm tắt</th>
                <th>Tác giả</th>
                <th>Trạng thái</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        <?php if(!in_array($data, array(null, '', '0'))):?>
            <?php foreach($data AS $key=>$value): ?>
                <tr>
                	<td class="centeralign"><input type="checkbox" /></td>
                    <td><?php echo $value->title; ?></td>
                    <td class="imet"><img style="height:100px;width:100px;" src="<?php echo $imgbase.$value->image; ?>"/></td>
                    <td><?php echo $value->summary; ?></td>
                    <td><?php echo $value->username; ?></td>
                    <td>
                        <?php if($value->active == 1): ?>
                            <i class="icon-star"></i> <span style="color: #46a73e;">Đã kích hoạt</span>
                        <?php else: ?>
                            <i class=" icon-star-empty"></i> Chưa kích hoạt
                        <?php endif;?>
                    </td>
                    <td class="centeralign">
                        <?php if($value->active == 1): ?>
                            <a data-id="<?php echo $value->id?>" class="de-active-x"><i class="icon-off"></i></a>
                        <?php else: ?>
                            <a data-id="<?php echo $value->id?>" class="active-x"><i class="icon-ok"></i></a>
                        <?php endif;?>
                        <a href="<?php echo $baseurl.'manage/incentive/edit-incentives/'.$value->id?>"><i class="icon-edit"></i></a>
                        <a data-id="<?php echo $value->id?>" class="deleterow-x"><i class="icon-trash"></i></a>
                    </td>
                </tr>
            <?php endforeach;?>
        </tbody>
    </table>
    
        <div class="pagination">
            <?php echo $this->pagination->create_links();?> 
        </div>
        <?php else: ?>
            </tbody>
        </table>
        <?php endif;?>
    
    </div>
</div>




<script>

jQuery('.deleterow-x').click(function(){
    var ids = $(this).data('id');
	var conf = confirm('Bạn muốn xóa ưu đãi này?');
	if(conf)
		jQuery(this).parents('tr').fadeOut(function(){
			jQuery(this).remove();
			$.ajax({
                type: "GET",
			    url: baseUrl+'manage/incentive/delete-incentives',
                data: ({id : ids})
			});
		});
	return false;
});

jQuery('.de-active-x').click(function(){
    var ids = $(this).data('id');
	var conf = confirm('Bạn muốn hủy kích hoạt ưu đãi này?');
	if(conf)
		$.ajax({
            type: "GET",
		    url: baseUrl+'manage/incentive/active-incentives',
            data: ({id : ids}),
            success: function(data)
            {
                setTimeout(function(){window.location.reload();}, 300);
            }
		});
	return false;
});
jQuery('.active-x').click(function(){
    var ids = $(this).data('id');
	var conf = confirm('Bạn muốn kích hoạt ưu đãi này?');
	if(conf)
		$.ajax({
            type: "GET",
		    url: baseUrl+'manage/incentive/active-incentives',
            data: ({id : ids}),
            success: function(data)
            {
                setTimeout(function(){window.location.reload();}, 300);
            }
		});
	return false;
});

</script>